package com.zkyc.framework.user.controller;

import com.zkyc.framework.common.Enum.LogType;
import com.zkyc.framework.common.annotation.Cache;
import com.zkyc.framework.common.annotation.Log;
import com.zkyc.framework.common.vo.ResultVO;
import com.zkyc.framework.common.vo.role.RolePageDto;
import com.zkyc.framework.common.vo.role.RoleWebsiteVo;
import com.zkyc.framework.user.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * (Role)表控制层
 *
 * @author wj
 * @since 2022-05-25 16:19:48
 */
@RestController
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 分页查询角色列表
     *
     * @return
     */
    @PostMapping("list")
    public ResultVO getRoleList(@RequestBody RolePageDto rolePageDto) {
        return roleService.getRoleList(rolePageDto);
    }


    /**
     * 新增角色
     */
    @Log(type = LogType.新建角色)
    @PostMapping("save")
    public ResultVO add(@RequestBody RoleWebsiteVo roleWebsiteVo) {
        return roleService.insert(roleWebsiteVo);
    }

    /**
     * 编辑角色
     */
    @Log(type = LogType.编辑角色)
    @PostMapping("edit")
    public ResultVO edit(@RequestBody RoleWebsiteVo roleWebsiteVo) {
        return roleService.update(roleWebsiteVo);
    }

    /**
     * 删除角色
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("delete")
    public ResultVO deleteById(Integer id) {
        return roleService.deleteById(id);
    }



    /**
     * 启用或禁用
     *
     * @param roleId
     * @return
     */
    @Log(type = LogType.启用禁用角色)
    @GetMapping("forbidden")
    public ResultVO forbidden(@RequestParam Integer roleId, @RequestParam Integer status) {
        return roleService.forbidden(roleId, status);
    }

    /**
     * 查看角色相关信息
     */
    @Cache
    @GetMapping("queryRoleInfo")
    public ResultVO queryRoleInfo(@RequestParam Integer roleId) {
        return roleService.queryRoleInfo(roleId);
    }

    /**
     * 查询网站列表
     */
    @GetMapping("queryWebsiteList")
    public ResultVO queryWebsiteList(@RequestParam String userId) {
        return roleService.queryWebsiteList(userId);
    }



    /**
     * 查询网站权限(手动设置的网站权限)
     *
     * @param websiteId
     * @return
     */
    @GetMapping("queryWebsiteRight")
    public ResultVO queryWebsiteRight(@RequestParam Integer websiteId) {
        return roleService.queryWebsiteRight(websiteId);
    }

    /**
     * 新增用户时   获取用户所在网站管理员权限的所有角色
     *
     * @param userId
     * @return
     */
    @GetMapping("queryAllRoleListByUserId")
    public ResultVO queryAllRoleListByUserId(@RequestParam String userId) {
        return roleService.queryAllRoleListByUserId(userId);
    }

    /**
     * 新增网站为新网站添加管理员并给超级管理员设置该网站的权限
     *
     * @param websiteId
     * @return
     */
    @GetMapping("addWebsiteRightList")
    public ResultVO addWebsiteRole(@RequestParam Integer websiteId, @RequestParam String websiteName, @RequestParam String userId) {
        return roleService.addWebsiteRole(websiteId, websiteName, userId);
    }

    /**
     * 获取按钮权限的树形列表
     *
     * @return
     */
    @GetMapping("getTreeData")
    public ResultVO getTreeData() {
        return roleService.getTreeData();
    }


    @GetMapping("getRoleMenu")
    public ResultVO getRoleMenu(@RequestParam Integer roleId) {
        return roleService.getRoleMenu(roleId);
    }

    @GetMapping("getMenuByRight")
    public ResultVO getMenuByRight(@RequestParam List<Integer> rightIdList) {
        return roleService.getMenuByRight(rightIdList);
    }

    @GetMapping("getDataRight")
    public String getDataRight(@RequestParam String websiteId, @RequestParam String userId) {
        return roleService.getDataRight(websiteId,userId);
    }

}

